package com.xiguthings.waka.service.sysconfig.impl;

import com.xiguthings.waka.dao.mapper.SysConfigMapper;
import com.xiguthings.waka.exception.BussinessException;
import com.xiguthings.waka.po.SysConfig;
import com.xiguthings.waka.po.SysConfigExample;
import com.xiguthings.waka.po.extpo.Page;
import com.xiguthings.waka.publicUtils.StringUtils;
import com.xiguthings.waka.service.sysconfig.ISysConfigService;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class SysConfigServiceImpl implements ISysConfigService {

    @Resource
    private SysConfigMapper sysConfigMapper;


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public int countByExample(SysConfigExample sysConfigExample) throws Exception {
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int deleteByExample(SysConfigExample sysConfigExample) throws Exception {
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int deleteByPrimaryKey(String id) throws Exception {
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int insert(SysConfig sysConfig) throws Exception {
        String id = StringUtils.getRandomUUID();
        sysConfig.setConfigId(id);
        return sysConfigMapper.insert(sysConfig);
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int insertSelective(SysConfig sysConfig) throws Exception {
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<SysConfig> selectByExample(SysConfigExample sysConfigExample) throws Exception {
        return sysConfigMapper.selectByExample(sysConfigExample);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public SysConfig selectByPrimaryKey(String id) throws Exception {
        return null;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByExampleSelective(SysConfig sysConfig, SysConfigExample sysConfigExample) throws Exception {
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByExample(SysConfig sysConfig, SysConfigExample sysConfigExample) throws Exception {
        return 0;
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByPrimaryKeySelective(SysConfig sysConfig) throws Exception {
        sysConfig.setCode(null);
        return sysConfigMapper.updateByPrimaryKeySelective(sysConfig);
    }

    @Override
    @Transactional(readOnly = false, isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public int updateByPrimaryKey(SysConfig sysConfig) throws Exception {
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page selectByPage(Page pageEntity, SysConfigExample sysConfigExample) throws Exception {
        return null;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public SysConfig selectByCode(String code) throws Exception {
        if (StringUtils.isBlank(code)) {
            BussinessException.throwThis(CODE_EMPTY_REQUIRED, "code不能为空");
        }
        SysConfigExample example = new SysConfigExample();
        SysConfigExample.Criteria criteria = example.createCriteria();
        criteria.andCodeEqualTo(code);
        List<SysConfig> list = sysConfigMapper.selectByExample(example);
        if (list != null || list.size() > 0) {
            return list.get(0);
        }
        return null;
    }


}
